import { getOne, update, remove, insert, list, getUserId } from "./request";

const USER_TABLE_NAME = "z5220833_starnight_user"
const LOG_TABLE_NAME = "z5220833_starnight_log"
const EXAM_TABLE_NAME = "z5220833_starnight_exam"
const QUESTION_TABLE_NAME = "z5220833_starnight_question"
const ANSWER_TABLE_NAME = "z5220833_starnight_answer"

export function insertLog(params: object): Promise<any> {
    return insert(LOG_TABLE_NAME, params)
}

export function listLog(limit: number = 10): Promise<any> {
    return list(LOG_TABLE_NAME, {userId: getUserId()}, limit)
}

export function listExam(type: number = 0, limit: number = 10): Promise<any> {
    return list(EXAM_TABLE_NAME, {type}, limit)
}

export function getExamById(examId: string): Promise<any> {
    return getOne(EXAM_TABLE_NAME, {objectId: examId})
}

export function getQuestionById(questionId: string): Promise<any> {
    return getOne(QUESTION_TABLE_NAME, {objectId: questionId})
}

export function insertAnswer(params: object): Promise<any> {
    return insert(ANSWER_TABLE_NAME, params)
}

export function getErrorQuestion() {
    return list(ANSWER_TABLE_NAME, {userId: getUserId(), doRight: false})
}

export function getErrorQuestionByTitle(title: string) {
    return list(ANSWER_TABLE_NAME, {userId: getUserId(), title: title})
}
